﻿﻿
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
    <link rel="stylesheet" type="text/css" href="style/login.css" />
    <script src="js/jquery-3.1.1.min.js"></script>
    <script>


        function login(){
            var username  = $('#username').val();
            var str = {
                "username":$('#username').val(),
                "password":$('#password').val()
            };
            $.ajax({
                type: "post",
                dataType: "json",
                url: "/login",
                contentType: "application/json;charset=utf-8;",
                data:JSON.stringify(str),
                success: function (data) {

                 /*   if(username == 'yang' || username == 'guest')
                    {
                        window.location.href = "/index";
                    }
                    else
                    {
                        window.location.href = "/indexmanual";
                    }
*/



                    window.location.href = "/optionList";



                }
            });

        }


        function register(){
            var username = $('#usernameR').val();
            var password1 = $('#passwordR1').val();
            var password2 = $('#passwordR2').val();

            if(password1 != password2 && password1 == '')
            {
                alert("两次输入的密码不一致");
                return;
            }




            var str = {
                "username":username,
                "password":password1
            };
            $.ajax({
                type: "post",
                dataType: "json",
                url: "/register",
                contentType: "application/json;charset=utf-8;",
                data:JSON.stringify(str),
                success: function (data) {
                    console.log(data);
                    var myInfo = data['msg'];
                    if(myInfo == '注册失败')
                    {
                    alert("注册失败：用户名已存在");}
                    else{
                        alert("注册成功，请登录");
                        window.location.href = "/toLogin";
                    }


                }
            });

        }

    </script>
</head>
<body>
<div class="waves"></div>
<script src="js/login.js"></script>
    <div class="login-wrap">
        <div class="login-html">
            <h2>ERP财务虚拟仿真实验</h2>

            <input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" class="tab">登录</label>
            <input id="tab-2" type="radio" name="tab" class="sign-up"><label for="tab-2" class="tab">注册</label>

            <div class="login-form">

                <div class="sign-in-htm">
                    <div class="group">
                        <label for="username" class="label">用户名</label>
                        <input id="username" type="text" class="input">
                    </div>
                    <div class="group">
                        <label for="password" class="label">密码</label>
                        <input id="password" type="password" class="input" data-type="password">
                    </div>
                  <!--  <div class="group">
                        <input id="check" type="checkbox" class="check" checked>
                        <label for="check"><span class="icon"></span> 保存当前用户状态信息</label>
                    </div>-->
                    <div class="group">
                        <input type="submit" class="button" value="登录" onclick="login()">

                    </div>
                    <div class="hr"></div>
                   <!-- <div class="foot-lnk">
                        <a href="#forgot">忘记密码?</a>
                    </div>-->
                </div>
                <div class="sign-up-htm">
                    <div class="group">
                        <label for="usernameR" class="label">用户名</label>
                        <input id="usernameR" type="text" class="input">
                    </div>
                    <div class="group">
                        <label for="passwordR1" class="label">密码</label>
                        <input id="passwordR1" type="password" class="input" data-type="password">
                    </div>
                    <div class="group">
                        <label for="passwordR2" class="label">再输入一次</label>
                        <input id="passwordR2" type="password" class="input" data-type="password">
                    </div>
                    <div class="group">
                        <label for="mailaddress" class="label">邮箱地址（可选）</label>
                        <input id="mailaddress" type="text" class="input">
                    </div>
                    <div class="group">
                        <input type="submit" class="button" value="注册账号" onclick="register()">
                    </div>
                </div>
            </div>
        </div>
    </div>
<div style="text-align:center;margin:10px 0; font:normal 14px/24px 'MicroSoft YaHei';color:#ffffff">
</div>
</body>
</html>